import { message } from 'ant-design-vue'
import dayjs, { Dayjs } from 'dayjs'

// 复制
function copyText(txt: string) {
  if (!txt) {
    return
  }
  var input = document.createElement('input')
  input.value = txt
  document.body.appendChild(input)
  input.select()
  document.execCommand('Copy')
  document.body.removeChild(input)
  message.success('复制成功')
}
// 格式化时间
function formatTimeForService(value: Dayjs, type?: 'start' | 'end') {
  if (!value) {
    return undefined
  }
  if (type === 'start') {
    return dayjs(dayjs(value).format('YYYY-MM-DD 00:00:00')).valueOf()
  }
  if (type === 'end') {
    return dayjs(dayjs(value).format('YYYY-MM-DD 23:59:59')).valueOf()
  }
  return dayjs(value).valueOf()
}
function formCentToYuan(value: number) {
  if (!value) {
    return 0
  }
  return value / 100
}
export {
  copyText,
  formatTimeForService,
  formCentToYuan
}